<?php

namespace app\common\model\system;
use app\common\model\BaseModel;

class SystemRole extends BaseModel
{

    public static function tablePK(): ?string
    {
        return 'role_id';
    }

    public static function tableName(): string
    {
        return 'system_role';
    }

    public function ruleNames($isArray = false)
    {
        $menusName = SystemMenu::getDB()->whereIn('menu_id', $this->rules)->column('menu_name');
        return $isArray ? $menusName : implode(',', $menusName);
    }


    public function getRulesAttr($value)
    {
        return array_map('intval', explode(',', $value));
    }


    public function setRulesAttr($value)
    {
        return implode(',', $value);
    }

}